#ifndef __UV_COMMON_H__
#define __UV_COMMON_H__

#ifdef __cplusplus
extern "C" {
#endif

#if _WIN32
#include <winsock2.h>
#include "win/win.h"
#else
#include <sys/types.h>
#include <sys/socket.h>
#include "unix/unix.h"
#endif
#include <stdint.h>


    typedef struct uv_buf_t {
        uint32_t len;
        char* base;
    } uv_buf_t;

    typedef enum OpType{
        RECV = 0,
        SEND = 1,
        SHUTDOWN = 2,
        LISTEN
    }OpType;


    typedef struct ReqCommon {
        REQCOMMON
    }ReqCommon_t;


    typedef struct RecvReq RecvReq_t;
    typedef struct SendReq SendReq_t;

    typedef void(*uv_send_cb)(SendReq_t * req, int status);
    typedef void(*uv_recv_cb)(RecvReq_t* handle, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned flags);
    typedef void(*uv_shutdown_cb)(ReqCommon_t* req, int status);
    typedef void(*uv_close_cb)(ReqCommon_t* req, int status);

    struct SendReq{
        REQCOMMON
        uv_buf_t buf; //内部使用，异步发送剩余数据
    };


    struct RecvReq {
        REQCOMMON
        uv_recv_cb cb;
        int started;
    };


#define RECVBUFLEN 4096u
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
void hookSignal();
#ifdef __cplusplus
}
#endif
#endif // !__UV_COMMON_H__


